package com.rjwh.dingdong.client.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.aishua.lib.utils.AsStrUtils;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.rjwh.dingdong.client.R;
import com.rjwh.dingdong.client.bean.localbean.DrawBookMainPageTopic;
import com.rjwh.dingdong.client.util.PicPathUtil;
import com.rjwh.dingdong.client.util.ViewHolder;
import com.wby.base.AdapterBase;

/**
 * Created by Kay on 2016-6-3.
 */
public class DrawBookTopicAdapter extends AdapterBase<DrawBookMainPageTopic> {

    private Context mContext;
    private LayoutInflater inflater;

    public DrawBookTopicAdapter(Context mContext) {
        this.mContext = mContext;
        inflater = LayoutInflater.from(mContext);
    }

    @Override
    protected View getExView(int i, View view, ViewGroup viewGroup) throws Exception {
        if (view == null) {
            view = inflater.inflate(R.layout.draw_book_topic_item, null);
        }
        ImageView topic_pic = ViewHolder.get(view, R.id.draw_book_topic_item_pic);
        TextView topic_title = ViewHolder.get(view, R.id.draw_book_topic_item_title);
        TextView topic_content = ViewHolder.get(view, R.id.draw_book_topic_item_content);

        DrawBookMainPageTopic getDrawBookDetailTopic = mList.get(i);
        if (getDrawBookDetailTopic == null) {
            return view;
        }

        String image = getDrawBookDetailTopic.getIcon();
        String introduction = getDrawBookDetailTopic.getIntroduction();
        String title = getDrawBookDetailTopic.getTitle();

        if (!AsStrUtils.isEmpty(image)) {
            Glide.with(mContext).load(PicPathUtil.getPicUrl(image))
                    .placeholder(R.drawable.icon_pic_holder).error(R.drawable.icon_pic_holder).dontAnimate().diskCacheStrategy(DiskCacheStrategy.ALL).into(topic_pic);
        }
        if (!AsStrUtils.isEmpty(title)) {
            topic_title.setText(title);
        }
        if (!AsStrUtils.isEmpty(introduction)) {
            topic_content.setText(introduction);
        }

        return view;
    }

    @Override
    protected void onReachBottom() {

    }
}
